package com.lineage.server.datatables;

import com.lineage.DatabaseFactory;
import com.lineage.server.utils.PerformanceTimer;
import com.lineage.server.utils.SQLUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ItemdropTable {
  private static final Log _log = LogFactory.getLog(ItemdropTable.class);
  
  private static ItemdropTable _instance;
  
  public static final ArrayList<Integer> RESTRICTIONS = new ArrayList<>();
  
  public static ItemdropTable get() {
    if (_instance == null)
      _instance = new ItemdropTable(); 
    return _instance;
  }
  
  public void load() {
    PerformanceTimer timer = new PerformanceTimer();
    Connection con = null;
    PreparedStatement pstm = null;
    ResultSet rs = null;
    try {
      con = DatabaseFactory.get().getConnection();
      pstm = con.prepareStatement("SELECT * FROM `w_内挂中禁止打到的物品`");
      rs = pstm.executeQuery();
      while (rs.next()) {
        String itemid = rs.getString("itemid");
        RESTRICTIONS.add(Integer.valueOf(itemid));
      } 
    } catch (SQLException e) {
      _log.error(e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(rs);
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    } 
    _log.info("载入挂机限制掉落道具: " + RESTRICTIONS.size() + "(" + timer.get() + "ms)");
  }
}
